package com.ybkj.daijia.api.aliyun.orc;

import com.alibaba.fastjson.JSONObject;
import com.ybkj.daijia.api.OcrApi;
import com.ybkj.daijia.api.OcrStrategy;
import com.ybkj.daijia.api.driver.ErrorConstant;
import java.util.Map;
import lombok.Getter;
import lombok.Setter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/***
 * 项目需要使用的阿里云api
 * @author zhyu
 * @date 2019-12-26 17:05:40
 */

public class AliyunOcrApi implements OcrApi {
    @Setter
    private Map<String, OcrStrategy> typeManager;
    @Override
    public JSONObject ocrCard(String type, String url) {
        if (type != null) {
            throw ErrorConstant.IMAGE_OCR_TYPE_ERROR.changeToCanThrowToUserException();
        }
        OcrStrategy ocr = typeManager.get(type);
        if (ocr != null) {
            return ocr.ocr(url);
        }
        throw ErrorConstant.IMAGE_OCR_TYPE_ERROR.changeToCanThrowToUserException();
    }
}
